<!--
 * @Description: 复制房间
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-05-13 10:51:03
 * @FilePath: /yuxiuproweb/src/views/mes/pro/workorder/mods/room/proRoom/copy.vue
-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    v-dialogDrag
    title="复制房间"
    :visible.sync="shows"
    width="400px"
    append-to-body
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="form"
      size="small"
      :inline="true"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item label="房间数" prop="creRoomNumber">
            <el-input-number
              v-model="form.creRoomNumber"
              placeholder="请输入房间数"
              style="width: 100%"
              clearable
              :min="0"
              :controls="false"
              :precision="0"
            ></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="shows = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addRoom } from "@/api/asc/room";
export default {
  props: {
    show: Boolean,
    type: {
      type: String,
      default: "add",
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      form: {
        creRoomNumber: undefined,
      },
      rules: {
        creRoomNumber: [
          { required: true, message: "请输入房间数", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  methods: {
    /** 提交按钮 */
    async submitForm() {
      try {
        await this.$refs["form"].validate();
        const { proRoomId, ...params } = {
          ...this.data,
          creRoomNumber: this.form.creRoomNumber,
        };
        addRoom(params).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.shows = false;
          this.$emit("update");
        });
      } catch (e) {
        console.log(e);
      }
    },
  },
};
</script>
